#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

//int main()
//{
//	printf("helloworld");
//	return 0;
//}

int minPathSum(int** matrix, int matrixRowLen, int* matrixColLen) {
    for (int i = 0; i < matrixRowLen; i++) {
        for (int j = 0; j < *matrixColLen; j++) {
            if (i == 0 && j != 0) {
                matrix[i][j] = matrix[i][j - 1] + matrix[i][j];
            }
            else if (j == 0 && i != 0) {
                matrix[i][j] = matrix[i - 1][j] + matrix[i][j];
            }
            else if (i == 0 && j == 0) {
                matrix[i][j] = matrix[i][j];
            }
            else {
                matrix[i][j] = (matrix[i][j - 1] + matrix[i][j]) > (matrix[i - 1][j] + matrix[i][j]) ? matrix[i - 1][j] + matrix[i][j] : matrix[i][j - 1] + matrix[i][j];
            }
        }
    }
    return matrix[matrixRowLen - 1][(*matrixColLen) - 1];
}
